<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>订单管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/common/i/favicon.ico"/>
    <meta name="apple-mobile-web-app-title" content="订单管理"/>
    <link rel="stylesheet" href="Css/amazeui.min.css"/>
    <script src="Scripts/api.js"></script>
    <link rel="stylesheet" href="Css/app.css"/>
    <link rel="stylesheet" href="Css/font_783249_3hfdb7m5w0j.css">
    <script src="Scripts/jquery.min.js"></script>
    <script src="Scripts/font_783249_e5yrsf08rap.js"></script>
    <script src="Scripts/api.js"></script>
    <script>
        BASE_URL = 'https://demo.yiovo.com/';
        STORE_URL = 'index.php?s=/store';
    </script>
</head>

<body data-type="">
<div class="am-g tpl-g">
    <!-- 内容区域 start -->
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf" id="orderStatename">
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form class="toolbar-form" id="form-search" action="">
                            <input name="s" type="hidden" value="/store/order/complete_list">
                            <input name="dataType" type="hidden" value="complete">
                            <div class="am-u-sm-12 am-u-md-3">
                                <div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a class="j-export am-btn am-btn-success am-radius"
                                               href="javascript:void(0);">
                                                <i class="iconfont icon-daochu am-margin-right-xs"></i>订单导出
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-9">
                                <div class="am fr">

                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input name="order_no" class="am-form-field" type="text"
                                                   placeholder="请输入订单号" value="">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search"
                                                        type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="order-list am-scrollable-horizontal am-u-sm-12 am-margin-top-xs">
                        <table width="100%"
                               class="am-table am-table-centered&#10;                        am-text-nowrap am-margin-bottom-xs">
                            <thead>
                            <tr>
                                <th width="30%" class="goods-detail">商品信息</th>
                                <th width="10%">单价/数量</th>
                                <th width="15%">实付款</th>
                                <th>买家</th>
                                <th>交易状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="orderItemList">


                            </tbody>

                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"></div>
                        <div class="am-fr pagination-total am-margin-right">
                        </div>
                    </div>
                    <div id="pageitem" class="am-u-lg-12 am-cf">

                    </div>

                </div>

            </div>
        </div>
    </div>

    <script>

        var getParam = function (name) {
            var search = document.location.search;
            var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
            var matcher = pattern.exec(search);
            var items = null;
            if (null != matcher) {
                try {
                    items = decodeURIComponent(decodeURIComponent(matcher[1]));
                } catch (e) {
                    try {
                        items = decodeURIComponent(matcher[1]);
                    } catch (e) {
                        items = matcher[1];
                    }
                }
            }
            return items;
        };
        var orderstate = "all";
        orderstate = getParam('orderstate');

        var pagenum = getParam('pagenum');

        if (pagenum == null)
            pagenum = 1;

        var stateName;
        if (orderstate == "all" || orderstate == null) {//全部
            orderstate = "all";
            stateName = "全部订单列表";

        } else if (orderstate == "delivery") {//未发货的订单
            stateName = "未发货订单列表";

        } else if (orderstate == "receipt") {//待收货的订单
            stateName = "待收货订单列表";

        } else if (orderstate == "pay") {//待付款的订单
            stateName = "待付款订单列表";

        } else if (orderstate == "finish") {//完成的订单
            stateName = "已完成订单列表";

        }
        var topnamehtml = "<div class=\"widget-title am-cf\">" + stateName + "</div>";
        $("#orderStatename").append(topnamehtml);

        var ordernum;
        var getnumcallback = function (num) {
            ordernum = num;
        };

        var ImagePath = null;
        var getimageback = function (goodsImage) {
            if(goodsImage.length>0)
            ImagePath = goodsImage;
        };

        var destate = 0;
        var paystate = 0;
        var getgoodscallback = function (goods) {
            for (var i = 0; i < goods.length; i++) {
                var goodid = goods[i]['id'];
                var goodimage = null;
                var goodname = goods[i]['goods_name'];
                var goodprice = toDecimal2(goods[i]['goods_price']);
                var goodnum = goods[i]['total_num'];
                getOrderImageById(goodid, getimageback);
                goodimage = ImagePath;

                if (i == 0) {
                    var tmep_html = "<tr class=\"order-empty\">\n" +
                        "                                        <td colspan=\"6\"></td>\n" +
                        "                                    </tr>";//空白行
                    tmep_html += "<tr>\n" +
                        "                                        <td class=\"am-text-middle am-text-left\" colspan=\"6\">\n" +
                        "                                            <span class=\"am-margin-right-lg\"> " + ordertime + "</span>\n" +
                        "                                            <span class=\"am-margin-right-lg\">订单号：" + orderno + "</span>\n" +
                        "                                        </td>\n" +
                        "                                    </tr>";//订单头部
                    tmep_html += "<tr>\n" +
                        "                                        <td class=\"goods-detail am-text-middle\">\n" +
                        "                                            <div class=\"goods-image\">\n" +
                        "                                                <img alt=\"\" src=\"" + goodimage + "\">\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"goods-info\">\n" +
                        "                                                <p class=\"goods-title\">" + goodname + "</p>\n" +
                        "                                            </div>\n" +
                        "                                        </td>\n" +
                        "                                        <td class=\"am-text-middle\">\n" +
                        "                                            <p>￥" + goodprice + "</p>\n" +
                        "                                            <p>×" + goodnum + "</p>\n" +
                        "                                        </td>\n" +
                        "                                        <td class=\"am-text-middle\" rowspan=\"" + ordernum + "\">\n" +
                        "                                            <p>￥" + paypricego + "</p>\n" +
                        "                                            <p class=\"am-link-muted\">(含运费：￥" + eprice + ")</p>\n" +
                        "                                        </td>\n" +
                        "                                        <td class=\"am-text-middle\" rowspan=\"" + ordernum + "\">\n" +
                        "                                            <p>用户id：" + userid + "</p>\n" +
                        "                                        </td>\n" +
                        "                                        <td class=\"am-text-middle\" rowspan=\"" + ordernum + "\" id=\"orderStateList\">\n" +
                        "\n" + payhtml + dhtml + rhtml +
                        "                                        </td>\n" +
                        "                                        <td class=\"am-text-middle\" rowspan=\"" + ordernum + "\">\n" +
                        "                                            <div class=\"tpl-table-black-operation\" id=\"isdelivery\">\n" +
                        "                                                <a class=\"tpl-table-black-operation-green\" href=\"/admin/OrderDate.html?orderid=" + oid + "\">\n" +
                        "                                                    订单详情</a>\n" ;

                    if(destate==0&&paystate==1){
                        tmep_html+="                                                <a class=\"tpl-table-black-operation-red\" href=\"/admin/delivery.html?orderid=" + oid + "\">\n" +
                            "                                                    发货</a>\n";
                    }
                    tmep_html+="                                            </div>\n" +
                        "                                        </td>\n" +
                        "                                    </tr>";//
                    $("#orderItemList").append(tmep_html);

                } else {
                    var goodhtml = "<tr>\n" +
                        "                                        <td class=\"goods-detail am-text-middle\">\n" +
                        "                                            <div class=\"goods-image\">\n" +
                        "                                                <img alt=\"\" src=\"" + goodimage + "\">\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"goods-info\">\n" +
                        "                                                <p class=\"goods-title\">" + goodname + "</p>\n" +
                        "                                                <p class=\"goods-spec am-link-muted\"></p>\n" +
                        "                                            </div>\n" +
                        "                                        </td>\n" +
                        "                                        <td class=\"am-text-middle\">\n" +
                        "                                            <p>￥" + goodprice + "</p>\n" +
                        "                                            <p>×" + goodnum + "</p>\n" +
                        "                                        </td>\n" +
                        "                                    </tr>";
                    $("#orderItemList").append(goodhtml);

                }


            }
            ordernum = 0;
        };
        var ordertime = null;
        var orderno = null;
        var paypricego = null;
        var eprice = null;
        var userid = null;
        var payhtml = null;
        var dhtml = null;
        var rhtml = null;
        var oid = null;

        var getOrdercallback = function (wxhelpdata) {
            for (var n = 0; n < wxhelpdata['rows'].length; n++) {
                var hid = wxhelpdata['rows'][n]['id'];
                oid = hid;
                var ono = wxhelpdata['rows'][n]['order_no'];
                var odates = wxhelpdata['rows'][n]['create_time'];
                var odate = dateToStr(new Date(odates));
                var totalprice = toDecimal2(wxhelpdata['rows'][n]['total_price']);//总共金额
                var payprice = toDecimal2(wxhelpdata['rows'][n]['pay_price']);//实付金额
                var expressprice = toDecimal2(wxhelpdata['rows'][n]['express_price']);//快递金额
                var uid = wxhelpdata['rows'][n]['user_id'];
                var paystatus = parseInt(wxhelpdata['rows'][n]['pay_status']);//支付状态
                var deliverystatus = parseInt(wxhelpdata['rows'][n]['delivery_status']);//快递状态
                var receiptstatus = parseInt(wxhelpdata['rows'][n]['receipt_status']);//接收状态
                var orderstatus = parseInt(wxhelpdata['rows'][n]['order_status']);//订单状态

                var paystatehtml = null;

                var deliverystatushtml = null;

                var receiptstatushtml = null;

                var orderstatushtml = null;

                ordertime = odate;
                orderno = ono;
                paypricego = payprice;
                eprice = expressprice;
                userid = uid;


                if (paystatus == 20) {
                    paystate = 1;
                    paystatehtml = "<p>付款状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                am-badge-success\">\n" +
                        "                                                        已付款</span>\n" +
                        "                                            </p>";
                } else {
                    paystate = 0;
                    paystatehtml = "<p>付款状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                \">\n" +
                        "                                                        待付款</span>\n" +
                        "                                            </p>";
                }
                if (deliverystatus == 20) {
                    destate = 1;
                    deliverystatushtml = "<p>发货状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                am-badge-success\">\n" +
                        "                                                        已发货</span>\n" +
                        "                                            </p>";

                } else {
                    destate = 0;
                    deliverystatushtml = "<p>发货状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                \">\n" +
                        "                                                        待发货</span>\n" +
                        "                                            </p>";
                }
                if (receiptstatus == 10) {
                    receiptstatushtml = "<p>收货状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                \">\n" +
                        "                                                        待收货</span>\n" +
                        "                                            </p>";

                } else {
                    receiptstatushtml = "<p>收货状态：\n" +
                        "                                                <span class=\"am-badge&#10;                                                am-badge-success\">\n" +
                        "                                                        已收货</span>\n" +
                        "                                            </p>";
                }

                payhtml = paystatehtml;
                dhtml = deliverystatushtml;
                rhtml = receiptstatushtml;

                getgoodsNum(hid, getnumcallback);
                getgoods(hid, getgoodscallback);

            }

            var allnum = parseInt(wxhelpdata['total']);
            var pageallnum = parseInt(Math.ceil(allnum / 10));
            pagenum = parseInt(pagenum);

            var pagehtml = "<div class=\"am-fr\">\n" +
                "                            <ul class=\"pagination\">";
            if (pagenum == 1) {
                pagehtml += "<li class=\"disabled\">\n" +
                    "                                    <span>«</span>\n" +
                    "                                </li>\n" +
                    "                                <li class=\"active\">\n" +
                    "                                    <span>1</span>\n" +
                    "                                </li>";
            } else if (pagenum <= 5) {
                pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + (pagenum - 1) + "\"" + ">«</a>\n" +
                    "                                </li>";
                for (var i = 1; i < pagenum; i++) {
                    pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + i + "\"" + ">" + i + "</a>\n" +
                        "                                </li>";
                }
                pagehtml += "<li class=\"active\">\n" +
                    "                                    <span>" + pagenum + "</span>\n" +
                    "                                </li>";
            } else {
                pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + (pagenum - 1) + "\"" + ">«</a>\n" +
                    "                                </li>";
                pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=1\"" + ">1</a>\n" +
                    "                                </li>";
                pagehtml += "<li class=\"disabled\"><span>...</span>\n" +
                    "                                </li>";
                for (var i = pagenum - 3; i < pagenum; i++) {
                    pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + i + "\"" + ">" + i + "</a>\n" +
                        "                                </li>";
                }
                pagehtml += "<li class=\"active\">\n" +
                    "                                    <span>" + pagenum + "</span>\n" +
                    "                                </li>";
            }

            if (pagenum == pageallnum) {
                pagehtml += "<li class=\"disabled\">\n" +
                    "                                    <span>»</span>\n" +
                    "                                </li>";
            } else if (pageallnum - 4 < pagenum) {

                for (var i = pagenum + 1; i <= pageallnum; i++) {
                    pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + i + "\"" + ">" + i + "</a>\n" +
                        "                                </li>";
                }
                pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + (pagenum + 1) + "\"" + ">»</a>\n" +
                    "                                </li>";

            } else {
                for (var i = pagenum + 1; i <= pagenum + 3; i++) {
                    pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + i + "\"" + ">" + i + "</a>\n" +
                        "                                </li>";
                }
                pagehtml += "<li class=\"disabled\"><span>...</span>\n" +
                    "                                </li>";

                pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + pageallnum + "\"" + ">" + pageallnum + "</a>\n" +
                    "                                </li>";
                pagehtml += "<li><a href=\"/admin/Order.html?orderstate=" + orderstate + "&pagenum=" + (pagenum + 1) + "\"" + ">»</a>\n" +
                    "                                </li>";
            }
            pagehtml += "</ul>\n" +
                "                        </div>\n" +
                "                        <div class=\"am-fr pagination-total am-margin-right\">\n" +
                "                            <div class=\"am-vertical-align-middle\">总记录：" + allnum + "</div>\n" +
                "                        </div>";
            $("#pageitem").append(pagehtml);

        };
        getAllOrder(pagenum, orderstate, getOrdercallback);


        function dateToStr(datetime) {

            var year = datetime.getFullYear();
            var month = datetime.getMonth() + 1;
            var date = datetime.getDate();
            var hour = datetime.getHours();
            var minutes = datetime.getMinutes();
            var second = datetime.getSeconds();

            if (month < 10) {
                month = "0" + month;
            }
            if (date < 10) {
                date = "0" + date;
            }
            if (hour < 10) {
                hour = "0" + hour;
            }
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            if (second < 10) {
                second = "0" + second;
            }

            var time = year + "-" + month + "-" + date + " " + hour + ":" + minutes + ":" + second;
            return time;
        }

        //制保留2位小数，如：2，会在2后面补上00.即2.00
        function toDecimal2(x) {
            var f = parseFloat(x);
            if (isNaN(f)) {
                return false;
            }
            var f = Math.round(x * 100) / 100;
            var s = f.toString();
            var rs = s.indexOf('.');
            if (rs < 0) {
                rs = s.length;
                s += '.';
            }
            while (s.length <= rs + 2) {
                s += '0';
            }
            return s;
        }

    </script>


    <!-- 内容区域 end -->

</div>

</body>

</html>